{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "23231834",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import pickle\n",
    "from pathlib import Path\n",
    "from concurrent.futures import ProcessPoolExecutor, as_completed\n",
    "import traceback"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b846d308",
   "metadata": {},
   "source": [
    "# 参数指定"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "30d23bbd",
   "metadata": {},
   "outputs": [],
   "source": [
    "chunk_num = 30"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "00be6248",
   "metadata": {},
   "source": [
    "# 函数定义"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "e682c943",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 加载筛选出的列以及col为负的列\n",
    "with open ('factor_names.pkl','rb') as f:\n",
    "    factor_names = pickle.load(f)\n",
    "\n",
    "with open ('neg_factor_names.pkl','rb') as f:\n",
    "    neg_factor_names = pickle.load(f)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a07de289",
   "metadata": {},
   "outputs": [],
   "source": [
    "def load_sample_and_mapping(chunk_num):\n",
    "    \"\"\"生成示例数据和股票代码 → 整数索引映射表\"\"\"\n",
    "    with open (f'merged_chunk_{chunk_num - 1}.pkl','rb') as f:\n",
    "        sample_df = pickle.load(f)\n",
    "    print(\"样本数据集信息：\")   \n",
    "    display(sample_df.info())\n",
    "    display(sample_df.describe())\n",
    "\n",
    "    stock_to_int = {stock: idx for idx, stock in enumerate(sample_df.index.get_level_values('stock_code').unique(), 1)}\n",
    "    # int_to_stock = {idx: stock for stock, idx in stock_to_int.items()}\n",
    "\n",
    "    print(\"股票代码 → 整数索引映射表：\")\n",
    "    print(pd.Series(stock_to_int).tail(10))\n",
    "\n",
    "    # 存储\n",
    "    with open('stock_to_int.pkl', 'wb') as f:\n",
    "        pickle.dump(stock_to_int, f)\n",
    "    return sample_df, stock_to_int"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "458d0a4b",
   "metadata": {},
   "outputs": [],
   "source": [
    "def process_dataframe(df, stock_mapping):\n",
    "    \"\"\"\n",
    "    参数：\n",
    "        df: 输入DataFrame（带有date和stock_code双重索引）\n",
    "        stock_mapping: 股票代码到整数的映射字典\n",
    "    返回：\n",
    "        转换后的.content格式字符串\n",
    "    \"\"\"\n",
    "    # 步骤1：删除return_10d和return_20d任意一个为NaN的行\n",
    "    cleaned_df = df.dropna(subset=['return_10d', 'return_20d'], how='any')\n",
    "    \n",
    "    # 步骤2：重置索引并转换stock_code为整数，筛除相关性绝对值小于0.01的列并将相关性为负的取反\n",
    "    result_df = cleaned_df.reset_index()\n",
    "    result_df['stock_int'] = result_df['stock_code'].map(stock_mapping)\n",
    "    \n",
    "    # feature_cols = [col for col in result_df.columns \n",
    "    #                if col not in ['date', 'stock_code', 'stock_int']]\n",
    "    feature_cols = factor_names + ['return_10d', 'return_20d']\n",
    "    ordered_cols = ['date', 'stock_int'] + feature_cols\n",
    "    result_df = result_df[ordered_cols]\n",
    "    for col in ordered_cols:\n",
    "        if col in neg_factor_names:\n",
    "            result_df[col] = - result_df[col]\n",
    "    # print(result_df.columns)\n",
    "    \n",
    "    # 步骤3：转换为.content格式（带date列）\n",
    "    content_lines = []\n",
    "    for _, row in result_df.iterrows():\n",
    "        # 第一列为date（格式化为yyyy-mm-dd）\n",
    "        line = [row['date'].strftime('%Y-%m-%d')] \n",
    "        # 添加所有特征值（保留原始精度）\n",
    "        line.extend([f\"{val:.6f}\" if isinstance(val, (float, np.floating)) else str(val) \n",
    "                    for val in row[1:]])\n",
    "        content_lines.append(\"\\t\".join(map(str, line)))\n",
    "    \n",
    "    return \"\\n\".join(content_lines)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "b44a1d62",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "样本数据集信息：\n",
      "<class 'pandas.core.frame.DataFrame'>\n",
      "MultiIndex: 618585 entries, (Timestamp('2024-07-15 00:00:00'), '000001.SZ') to (Timestamp('2024-12-31 00:00:00'), '920128.BJ')\n",
      "Data columns (total 34 columns):\n",
      " #   Column          Non-Null Count   Dtype  \n",
      "---  ------          --------------   -----  \n",
      " 0   ret_5d          618585 non-null  float64\n",
      " 1   ret_21d         618585 non-null  float64\n",
      " 2   std_1m          618585 non-null  float64\n",
      " 3   vstd_1m         618585 non-null  float64\n",
      " 4   turn_1m         618585 non-null  float64\n",
      " 5   std_turn_1m     618585 non-null  float64\n",
      " 6   bias_turn_1m    618585 non-null  float64\n",
      " 7   std_ret_10d     618585 non-null  float64\n",
      " 8   std_vol_10d     618585 non-null  float64\n",
      " 9   std_turn_10d    618585 non-null  float64\n",
      " 10  corr_ret_close  618585 non-null  float64\n",
      " 11  corr_ret_open   618585 non-null  float64\n",
      " 12  corr_ret_high   618585 non-null  float64\n",
      " 13  corr_ret_low    618585 non-null  float64\n",
      " 14  corr_ret_vwap   618585 non-null  float64\n",
      " 15  corr_ret_vol    618585 non-null  float64\n",
      " 16  corr_ret_turn   618585 non-null  float64\n",
      " 17  corr_vol_close  618585 non-null  float64\n",
      " 18  corr_vol_open   618585 non-null  float64\n",
      " 19  corr_vol_high   618585 non-null  float64\n",
      " 20  corr_vol_low    618585 non-null  float64\n",
      " 21  low2high        618585 non-null  float64\n",
      " 22  vwap2close      618585 non-null  float64\n",
      " 23  kmid            618585 non-null  float64\n",
      " 24  klen_y          618585 non-null  float64\n",
      " 25  kmid2           618585 non-null  float64\n",
      " 26  kup             618585 non-null  float64\n",
      " 27  kup2            618585 non-null  float64\n",
      " 28  klow            618585 non-null  float64\n",
      " 29  klow2           618585 non-null  float64\n",
      " 30  ksft            618585 non-null  float64\n",
      " 31  ksft2           618585 non-null  float64\n",
      " 32  return_10d      539976 non-null  float64\n",
      " 33  return_20d      487793 non-null  float64\n",
      "dtypes: float64(34)\n",
      "memory usage: 162.9+ MB\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "None"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ret_5d</th>\n",
       "      <th>ret_21d</th>\n",
       "      <th>std_1m</th>\n",
       "      <th>vstd_1m</th>\n",
       "      <th>turn_1m</th>\n",
       "      <th>std_turn_1m</th>\n",
       "      <th>bias_turn_1m</th>\n",
       "      <th>std_ret_10d</th>\n",
       "      <th>std_vol_10d</th>\n",
       "      <th>std_turn_10d</th>\n",
       "      <th>...</th>\n",
       "      <th>klen_y</th>\n",
       "      <th>kmid2</th>\n",
       "      <th>kup</th>\n",
       "      <th>kup2</th>\n",
       "      <th>klow</th>\n",
       "      <th>klow2</th>\n",
       "      <th>ksft</th>\n",
       "      <th>ksft2</th>\n",
       "      <th>return_10d</th>\n",
       "      <th>return_20d</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>...</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>6.185850e+05</td>\n",
       "      <td>539976.000000</td>\n",
       "      <td>487793.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>1.585148e-18</td>\n",
       "      <td>-2.320290e-18</td>\n",
       "      <td>-1.470283e-18</td>\n",
       "      <td>-1.488661e-17</td>\n",
       "      <td>4.502740e-18</td>\n",
       "      <td>1.144064e-17</td>\n",
       "      <td>1.085482e-17</td>\n",
       "      <td>1.989476e-17</td>\n",
       "      <td>7.902768e-18</td>\n",
       "      <td>-1.654068e-18</td>\n",
       "      <td>...</td>\n",
       "      <td>3.629760e-18</td>\n",
       "      <td>1.562175e-17</td>\n",
       "      <td>-5.559506e-18</td>\n",
       "      <td>2.504075e-18</td>\n",
       "      <td>2.416777e-17</td>\n",
       "      <td>-6.983842e-18</td>\n",
       "      <td>-1.654068e-18</td>\n",
       "      <td>1.010819e-17</td>\n",
       "      <td>0.035646</td>\n",
       "      <td>0.083532</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>9.840151e-01</td>\n",
       "      <td>9.828825e-01</td>\n",
       "      <td>9.829104e-01</td>\n",
       "      <td>9.829104e-01</td>\n",
       "      <td>9.829104e-01</td>\n",
       "      <td>9.829104e-01</td>\n",
       "      <td>9.829104e-01</td>\n",
       "      <td>9.947119e-01</td>\n",
       "      <td>9.834654e-01</td>\n",
       "      <td>9.834654e-01</td>\n",
       "      <td>...</td>\n",
       "      <td>9.846966e-01</td>\n",
       "      <td>9.832327e-01</td>\n",
       "      <td>9.804147e-01</td>\n",
       "      <td>9.789808e-01</td>\n",
       "      <td>9.846966e-01</td>\n",
       "      <td>9.832327e-01</td>\n",
       "      <td>9.846966e-01</td>\n",
       "      <td>9.832327e-01</td>\n",
       "      <td>0.136402</td>\n",
       "      <td>0.212295</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>-3.231691e+00</td>\n",
       "      <td>-3.052217e+00</td>\n",
       "      <td>-1.074193e+00</td>\n",
       "      <td>-1.074193e+00</td>\n",
       "      <td>-1.359372e+00</td>\n",
       "      <td>-1.402825e+00</td>\n",
       "      <td>-2.015718e+00</td>\n",
       "      <td>-2.706521e+00</td>\n",
       "      <td>-1.097865e+00</td>\n",
       "      <td>-1.485234e+00</td>\n",
       "      <td>...</td>\n",
       "      <td>-3.111030e+00</td>\n",
       "      <td>-3.156838e+00</td>\n",
       "      <td>-2.101568e+00</td>\n",
       "      <td>-2.914414e+00</td>\n",
       "      <td>-2.207467e+00</td>\n",
       "      <td>-2.395897e+00</td>\n",
       "      <td>-3.233154e+00</td>\n",
       "      <td>-3.925268e+00</td>\n",
       "      <td>-0.435318</td>\n",
       "      <td>-0.482352</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>-5.721236e-01</td>\n",
       "      <td>-6.182109e-01</td>\n",
       "      <td>-7.888044e-01</td>\n",
       "      <td>-7.888044e-01</td>\n",
       "      <td>-7.560924e-01</td>\n",
       "      <td>-7.793382e-01</td>\n",
       "      <td>-4.407292e-01</td>\n",
       "      <td>-6.803221e-01</td>\n",
       "      <td>-7.918105e-01</td>\n",
       "      <td>-7.793825e-01</td>\n",
       "      <td>...</td>\n",
       "      <td>-7.124545e-01</td>\n",
       "      <td>-7.121926e-01</td>\n",
       "      <td>-7.322485e-01</td>\n",
       "      <td>-7.585707e-01</td>\n",
       "      <td>-7.278248e-01</td>\n",
       "      <td>-7.584937e-01</td>\n",
       "      <td>-5.512395e-01</td>\n",
       "      <td>-7.267309e-01</td>\n",
       "      <td>-0.038627</td>\n",
       "      <td>-0.037212</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>-4.772445e-02</td>\n",
       "      <td>-8.460052e-02</td>\n",
       "      <td>-3.774826e-01</td>\n",
       "      <td>-3.774826e-01</td>\n",
       "      <td>-3.212070e-01</td>\n",
       "      <td>-3.488145e-01</td>\n",
       "      <td>5.961062e-02</td>\n",
       "      <td>-2.010679e-01</td>\n",
       "      <td>-3.840869e-01</td>\n",
       "      <td>-3.606536e-01</td>\n",
       "      <td>...</td>\n",
       "      <td>-2.250670e-01</td>\n",
       "      <td>0.000000e+00</td>\n",
       "      <td>-2.133438e-01</td>\n",
       "      <td>-5.995093e-02</td>\n",
       "      <td>-1.847835e-01</td>\n",
       "      <td>-1.254676e-01</td>\n",
       "      <td>-2.541832e-03</td>\n",
       "      <td>-1.618867e-02</td>\n",
       "      <td>0.010927</td>\n",
       "      <td>0.036111</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>4.676920e-01</td>\n",
       "      <td>4.744453e-01</td>\n",
       "      <td>5.142483e-01</td>\n",
       "      <td>5.142483e-01</td>\n",
       "      <td>4.701171e-01</td>\n",
       "      <td>5.065649e-01</td>\n",
       "      <td>4.025847e-01</td>\n",
       "      <td>4.905177e-01</td>\n",
       "      <td>5.190229e-01</td>\n",
       "      <td>5.168322e-01</td>\n",
       "      <td>...</td>\n",
       "      <td>4.419675e-01</td>\n",
       "      <td>7.041410e-01</td>\n",
       "      <td>4.338644e-01</td>\n",
       "      <td>6.265512e-01</td>\n",
       "      <td>4.736046e-01</td>\n",
       "      <td>5.848774e-01</td>\n",
       "      <td>5.004845e-01</td>\n",
       "      <td>7.045151e-01</td>\n",
       "      <td>0.074313</td>\n",
       "      <td>0.153928</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>2.949716e+00</td>\n",
       "      <td>2.945807e+00</td>\n",
       "      <td>2.049274e+00</td>\n",
       "      <td>2.049274e+00</td>\n",
       "      <td>2.409806e+00</td>\n",
       "      <td>2.482871e+00</td>\n",
       "      <td>2.141490e+00</td>\n",
       "      <td>2.891046e+00</td>\n",
       "      <td>2.075075e+00</td>\n",
       "      <td>2.524622e+00</td>\n",
       "      <td>...</td>\n",
       "      <td>3.379605e+00</td>\n",
       "      <td>3.362561e+00</td>\n",
       "      <td>3.306359e+00</td>\n",
       "      <td>3.932961e+00</td>\n",
       "      <td>3.457692e+00</td>\n",
       "      <td>3.861506e+00</td>\n",
       "      <td>3.240570e+00</td>\n",
       "      <td>3.080418e+00</td>\n",
       "      <td>4.608497</td>\n",
       "      <td>8.585684</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>8 rows × 34 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "             ret_5d       ret_21d        std_1m       vstd_1m       turn_1m  \\\n",
       "count  6.185850e+05  6.185850e+05  6.185850e+05  6.185850e+05  6.185850e+05   \n",
       "mean   1.585148e-18 -2.320290e-18 -1.470283e-18 -1.488661e-17  4.502740e-18   \n",
       "std    9.840151e-01  9.828825e-01  9.829104e-01  9.829104e-01  9.829104e-01   \n",
       "min   -3.231691e+00 -3.052217e+00 -1.074193e+00 -1.074193e+00 -1.359372e+00   \n",
       "25%   -5.721236e-01 -6.182109e-01 -7.888044e-01 -7.888044e-01 -7.560924e-01   \n",
       "50%   -4.772445e-02 -8.460052e-02 -3.774826e-01 -3.774826e-01 -3.212070e-01   \n",
       "75%    4.676920e-01  4.744453e-01  5.142483e-01  5.142483e-01  4.701171e-01   \n",
       "max    2.949716e+00  2.945807e+00  2.049274e+00  2.049274e+00  2.409806e+00   \n",
       "\n",
       "        std_turn_1m  bias_turn_1m   std_ret_10d   std_vol_10d  std_turn_10d  \\\n",
       "count  6.185850e+05  6.185850e+05  6.185850e+05  6.185850e+05  6.185850e+05   \n",
       "mean   1.144064e-17  1.085482e-17  1.989476e-17  7.902768e-18 -1.654068e-18   \n",
       "std    9.829104e-01  9.829104e-01  9.947119e-01  9.834654e-01  9.834654e-01   \n",
       "min   -1.402825e+00 -2.015718e+00 -2.706521e+00 -1.097865e+00 -1.485234e+00   \n",
       "25%   -7.793382e-01 -4.407292e-01 -6.803221e-01 -7.918105e-01 -7.793825e-01   \n",
       "50%   -3.488145e-01  5.961062e-02 -2.010679e-01 -3.840869e-01 -3.606536e-01   \n",
       "75%    5.065649e-01  4.025847e-01  4.905177e-01  5.190229e-01  5.168322e-01   \n",
       "max    2.482871e+00  2.141490e+00  2.891046e+00  2.075075e+00  2.524622e+00   \n",
       "\n",
       "       ...        klen_y         kmid2           kup          kup2  \\\n",
       "count  ...  6.185850e+05  6.185850e+05  6.185850e+05  6.185850e+05   \n",
       "mean   ...  3.629760e-18  1.562175e-17 -5.559506e-18  2.504075e-18   \n",
       "std    ...  9.846966e-01  9.832327e-01  9.804147e-01  9.789808e-01   \n",
       "min    ... -3.111030e+00 -3.156838e+00 -2.101568e+00 -2.914414e+00   \n",
       "25%    ... -7.124545e-01 -7.121926e-01 -7.322485e-01 -7.585707e-01   \n",
       "50%    ... -2.250670e-01  0.000000e+00 -2.133438e-01 -5.995093e-02   \n",
       "75%    ...  4.419675e-01  7.041410e-01  4.338644e-01  6.265512e-01   \n",
       "max    ...  3.379605e+00  3.362561e+00  3.306359e+00  3.932961e+00   \n",
       "\n",
       "               klow         klow2          ksft         ksft2     return_10d  \\\n",
       "count  6.185850e+05  6.185850e+05  6.185850e+05  6.185850e+05  539976.000000   \n",
       "mean   2.416777e-17 -6.983842e-18 -1.654068e-18  1.010819e-17       0.035646   \n",
       "std    9.846966e-01  9.832327e-01  9.846966e-01  9.832327e-01       0.136402   \n",
       "min   -2.207467e+00 -2.395897e+00 -3.233154e+00 -3.925268e+00      -0.435318   \n",
       "25%   -7.278248e-01 -7.584937e-01 -5.512395e-01 -7.267309e-01      -0.038627   \n",
       "50%   -1.847835e-01 -1.254676e-01 -2.541832e-03 -1.618867e-02       0.010927   \n",
       "75%    4.736046e-01  5.848774e-01  5.004845e-01  7.045151e-01       0.074313   \n",
       "max    3.457692e+00  3.861506e+00  3.240570e+00  3.080418e+00       4.608497   \n",
       "\n",
       "          return_20d  \n",
       "count  487793.000000  \n",
       "mean        0.083532  \n",
       "std         0.212295  \n",
       "min        -0.482352  \n",
       "25%        -0.037212  \n",
       "50%         0.036111  \n",
       "75%         0.153928  \n",
       "max         8.585684  \n",
       "\n",
       "[8 rows x 34 columns]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "股票代码 → 整数索引映射表：\n",
      "920060.BJ    5370\n",
      "920066.BJ    5371\n",
      "920082.BJ    5372\n",
      "920088.BJ    5373\n",
      "920098.BJ    5374\n",
      "920099.BJ    5375\n",
      "920106.BJ    5376\n",
      "920111.BJ    5377\n",
      "920118.BJ    5378\n",
      "920128.BJ    5379\n",
      "dtype: int64\n",
      "chunk_1 processed.\n",
      "chunk_2 processed.\n",
      "chunk_3 processed.\n",
      "chunk_4 processed.\n",
      "chunk_5 processed.\n",
      "chunk_6 processed.\n",
      "chunk_7 processed.\n",
      "chunk_8 processed.\n",
      "chunk_9 processed.\n",
      "chunk_10 processed.\n",
      "chunk_11 processed.\n",
      "chunk_12 processed.\n",
      "chunk_13 processed.\n",
      "chunk_14 processed.\n",
      "chunk_15 processed.\n",
      "chunk_16 processed.\n",
      "chunk_17 processed.\n",
      "chunk_18 processed.\n",
      "chunk_19 processed.\n",
      "chunk_20 processed.\n",
      "chunk_21 processed.\n",
      "chunk_22 processed.\n",
      "chunk_23 processed.\n",
      "chunk_24 processed.\n",
      "chunk_25 processed.\n",
      "chunk_26 processed.\n",
      "chunk_27 processed.\n",
      "chunk_28 processed.\n",
      "chunk_29 processed.\n"
     ]
    }
   ],
   "source": [
    "if __name__ == '__main__':\n",
    "    sample_df, stock_to_int = load_sample_and_mapping(chunk_num)\n",
    "    processed_dir = Path('../processed_chunk')\n",
    "    processed_dir.mkdir(parents = True, exist_ok = True)\n",
    "\n",
    "    for i in range(1, chunk_num):\n",
    "        with open(f\"merged_chunk_{i}.pkl\", 'rb') as f:\n",
    "            df = pickle.load(f)\n",
    "\n",
    "        processed_dataframe = process_dataframe(df, stock_to_int)\n",
    "        filename = f'processed_chunk_{i}.content'\n",
    "        filepath = processed_dir / filename\n",
    "        with open(filepath, 'w') as f:\n",
    "            f.write(processed_dataframe)\n",
    "\n",
    "        print(f'chunk_{i} processed.')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "0f515a77",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "MTL",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
